var express  = require('express');
var guard = require('./coreframe/guard');
// const multer = require('multer');


// 
var app = express();

var ori = "http://localhost:5701/"
const PORT = 5701;




app.post('/', function(req ,res) {
    //不能正确解析json 格式的post参数
    let body = '', jsonStr = {} , resp = {};
    req.on('data', function (chunk) {
        body += chunk; //读取参数流转化为字符串
    });

    req.on('end', function () {
        //读取参数流结束后将转化的body字符串解析成 JSON 格式
        try {   jsonStr = JSON.parse(body); } 
        catch (err) {   jsonStr = null; }
        // console.log(jsonStr);

        // console.log("jsonstr"  , jsonStr);
        guard.guard(jsonStr,resp);
        res.json(resp);
        res.end();
    });
    
    // res.send("sucess")
})






var server = app.listen(PORT,function() {

  let host = server.address().address;
  let port = server.address().port;

  console.log(host,port);
});